let user = require('./User');
console.log(`userName:${user.userName}`);
console.log(`userName:${user.userName} - ${user.sayHello()}`);

let http = require('http');
let url = require('url');
let util = require('util');
let fs = require('fs');

let server = http.createServer((req,res)=>{
      res.statusCode = 200;

     // res.setHeader("Content-Type","text/plain;charset=utf-8");

      let  pathName = url.parse(req.url).pathname;
      fs.readFile(pathName.substring(1),function (err,data) {
         if(err){
           res.writeHead(404,{
             'Content-Type':'text/html;charset=utf-8'
           });
         }else{
           res.writeHead(200,{
             'Content-Type':'text/html;charset=utf-8'
           })
           res.write(data.toString());
         }
        res.end();//要在文件系统内部读取！
      });

      //res.end(util.inspect(url.parse(req.url)));


      //res.end(util.inspect(url.parse("http://localhost:3000/index?demo=123#tag")));
  }
);

server.listen(3000,'127.0.0.1',()=>{
  console.log("服务器已经运行，请打开浏览器，输入：http://127.0.0.1:3000/ 来进行访问");
});
